/*
 * p4048.cpp
 *
 *  Created on: 2013-5-20
 *      Author: zy
 */

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS = 1e-8;
int sig(double d)
{
	return fabs(d) < EPS ? 0 : d < 0 ? -1 : 1;
}
struct Point
{
	double x, y;
	bool friend operator ==(Point a, Point b)
	{
		return sig(a.x - b . x) == 0 && sig(a.y - b.y == 0);
	}
};
Point p[1505][2], a;//p[i][0]:end point1,p[i][1]:end point2;a:start point
int n;

int dot(Point o, Point a, Point b)
{
	return (a.x - o.x) * (b.x - o.x) + (a.y - o. y) * (b.y - o.y);
}
int btw(Point x, Point a, Point b)
{
	return sig(dot(x, a, b));
}
double cross(Point o, Point a, Point b)
{
	return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
bool segLineCross(Point a, Point b, Point c, Point d)
{
	double s1, s2;
	int d1, d2;
	Point p;
	d1 = sig(s1 = cross(a, b, c));
	d2 = sig(s2 = cross(a, b, d));
	if ((d1 ^ d2) == -2)
	{
		p.x = (c.x * s2 - d.x * s1) / (s2 - s1);
		p.y = (c.y * s2 - d.y * s1) / (s2 - s1);
		if (btw(b, a, p) <= 0 || btw(p, a, b) <= 0)
			return true;
	}
	else if (d1 == 0 && btw(c, a, b) <= 0 || d2 == 0 && btw(d, a, b) <= 0)
		return true;
	return false;
}
int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%lf%lf%lf%lf", &p[i][0].x, &p[i][0].y, &p[i][1].x,
					&p[i][1].y);
		scanf("%lf%lf", &a.x, &a.y);
		int ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= 1; j++)
			{
				int tem = 0;
				Point b = p[i][j];
				if (a == b)
					continue;
				for (int k = 1; k <= n; k++)
					if (segLineCross(a, b, p[k][0], p[k][1]))
						tem++;
				//printf("%d\n", tem);
				ans = max(ans, tem);
			}
		printf("%d\n", ans);
	}
	return 0;
}
